<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv=content-type content=text/html;charset=utf-8> 
<link rel="stylesheet" type="text/css" href="rule.css" />
<title>Demir Yayincilik</title>
<script>
var tum_makale_listesi;
var konu_listesi;
var bilim_dali_listesi;
var dergi_listesi;
var dergi_sayi_listesi;
var sayi_makale_listesi;

window.onload=function sessionKontrol(){
var xmlhttp;
	
	if (window.XMLHttpRequest)  	
 		 xmlhttp=new XMLHttpRequest(); 	 
  
	else  	
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	
	xmlhttp.onreadystatechange=function()
	{  
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
  			if(xmlhttp.responseText == 'admin')
  			{
  				window.location.href="admin.jsp";	

  			}
  			else if(xmlhttp.responseText == 'uye_acik'){
  				window.location.href="uye.jsp";	

  			}	
  			
  		}
  	}
	
	xmlhttp.open("GET","http://localhost:8080/yazgellab/sessionkontrol.action",true);
	xmlhttp.send(null);
}

function uyeOl(){
	
	if(document.getElementById("ad").value==""){
		alert("İsim alanı boş geçilemez");
	}
	
	else if(document.getElementById("soyad").value==""){
		alert("Soyad alanı boş geçilemez");
	}
	
	else if(document.getElementById("dogum_yeri").value==""){
		alert("Doğum yeri alanı boş geçilemez");
	}
	
	else if(document.getElementById("birth_day").value=="- Gün -" || document.getElementById("birth_month").value=="- Ay -" || document.getElementById("birth_year").value=="- Yıl -"){
		alert("Doğum tarihi alanı boş geçilemez");
	}
	
	else if(document.getElementById("meslek").value==""){
		alert("Meslek alanı boş geçilemez");
	}
	
	else{
		
		if(document.getElementById("sifre2").value==document.getElementById("tekrar_sifre").value){
		
			var parameter;
			parameter="ad="+document.getElementById("ad").value+"&";
			parameter+="soyad="+document.getElementById("soyad").value+"&";
			parameter+="e_mail="+document.getElementById("email").value+"&";
			parameter+="sifre="+document.getElementById("sifre2").value+"&";
			parameter+="dogum_yeri="+document.getElementById("dogum_yeri").value+"&";
			parameter+="dogum_tarihi="+document.getElementById("birth_day").value+"/"+document.getElementById("birth_month").value+"/"+document.getElementById("birth_year").value+"&";
			parameter+="ozgecmis="+document.getElementById("ozgecmis").value+"&";
			parameter+="meslek="+document.getElementById("meslek").value+"&";
			parameter+="unvan="+document.getElementById("unvan").value+"&";
			parameter+="uzmanlik_alani="+document.getElementById("uzmanlik_alani").value+"&";
			if(document.getElementById("rol_enable").checked==true){
				parameter+="rol_enable=1&";
				parameter+="rol_secimi="+document.getElementById("rolselect").value;
			}
			else{
				parameter+="rol_enable=0";
			}
			
			var xmlhttp;
			
			if (window.XMLHttpRequest)  	
		 		 xmlhttp=new XMLHttpRequest(); 	 
		  
			else  	
		  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			
			xmlhttp.onreadystatechange=function()
			{  
		  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		  			if(xmlhttp.responseText == 'basarili_giris')
		  			{
		  				window.location.href="uye.jsp";		
		  			}
		  			
		  		}
		  	}
			
			xmlhttp.open("GET","http://localhost:8080/yazgellab/uyeol.action?"+parameter,true);
			xmlhttp.send(null);
			
		}
		else{
			alert("Girdiğiniz şifreler uyumsuz");
			document.getElementById("sifre2").value="";
			document.getElementById("tekrar_sifre").value="";
		}
	}
}

function listele() {
	
	var xmlhttp;

	if (window.XMLHttpRequest) 
		xmlhttp=new XMLHttpRequest(); 

	else 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");


	xmlhttp.onreadystatechange=function()
	{ 
	if (xmlhttp.readyState==4 && xmlhttp.status==200){
		var code="";
		var counter;
		tum_makale_listesi=xmlhttp.responseText.split("|");
		if(tum_makale_listesi.length!=1){
			counter=(tum_makale_listesi.length-1)/5;
	
			code+='<table border="1" style="margin-top:30px">';
			code+='<tr><td><b>Başlık</b></td><td><b>Yayınlanma Yılı</b></td><td><b>Yazar</b></td><td>Makale Aç</td></tr>';
			for(var i=0;i<counter;i++){
				
				code+='<tr><td>'+tum_makale_listesi[i*5+1]+'</td><td>'+tum_makale_listesi[i*5+3]+'</td><td>'+tum_makale_listesi[i*5+4]+'</td><td><button type="button" onClick="makaleAc(\''+tum_makale_listesi[i*5+2]+'\','+tum_makale_listesi[i*5]+')">Makale Aç</button> </td></tr>';
	
			}
			code+="</table><br>";
		}
		else{
			code+='<p>Sisteme kayıtlı herhangi bir makale bulunmamaktadır</p>';
		}
	
		document.getElementById("panel").innerHTML=code;
		}
	}
	xmlhttp.open("GET","http://localhost:8080/yazgellab/listele.action",false);
	xmlhttp.send(null);	
}

function login()
{
	
	var xmlhttp;
	
	if (window.XMLHttpRequest)  	
 		 xmlhttp=new XMLHttpRequest(); 	 
  
	else  	
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	
  
	xmlhttp.onreadystatechange=function()
	{  
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
  			if(xmlhttp.responseText == 'basarili_giris')
  			{
  				window.location.href="uye.jsp";		
  			}
  			else if(xmlhttp.responseText == 'admin_girisi')
  			{
  				window.location.href="admin.jsp";		
  			}
  			else{
  				document.getElementById('login').innerHTML=document.getElementById('login').innerHTML+'<br>Hatalı giriş yaptınız';
  			}
  		}
  	}

	
	var checkBox=document.getElementById("admingirisi");
	var e_mail=document.getElementById("e_mail").value;
	var sifre=document.getElementById("sifre").value;
	
	var checked;
	if(checkBox.checked==false){
		checked=0;
	}
	
	else{
        checked=1;
	}
	
	xmlhttp.open("GET","http://localhost:8080/yazgellab/login.action?giris_tipi="+checked+"&e_mail="+e_mail+"&sifre="+sifre,true);
	xmlhttp.send(null);
}

function register() { 
    document.getElementById("panel").innerHTML = '<table width="00%" border="0" cellspacing="1" cellpadding="0"> <tr><td>Adı</td><td class="data"><input type="text" name="email" id="ad"></td></tr> <tr><td>Soyadı</td><td class="data"><input type="text" name="email" id="soyad"></td></tr> <tr><td>E posta Adresi</td><td class="data"><input type="text" name="email" id="email"></td></tr> <tr><td>Şifre</td><td class="data"><input type="password" name="email" id="sifre2"></td></tr> <tr><td>Şifre Tekrar</td><td class="data"><input type="password" name="email" id="tekrar_sifre"></td></tr> <tr><td>Doğum Yeri</td><td class="data"><input type="text" name="email" id="dogum_yeri"></td></tr> <tr><td>Doğum Tarihi</td><td class="data"> <select name="DateOfBirth_Day" id="birth_day"> <option> - Gün - </option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="DateOfBirth_Month" id="birth_month"> <option> - Ay - </option> <option value="1">Ocak</option> <option value="2">Şubat</option> <option value="3">Mart</option> <option value="4">Nisan</option> <option value="5">Mayıs</option> <option value="6">Haziran</option> <option value="7">Temmuz</option> <option value="8">Ağustos</option> <option value="9">Eylül</option> <option value="10">Ekim</option> <option value="11">Kasım</option> <option value="12">Aralık</option> </select> <select name="DateOfBirth_Year" id="birth_year"> <option> - Yıl - </option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> <option value="1900">1900</option> </select> </td></tr> <tr><td>Öz Geçmiş<br><br><br><br></td><td method="post" action=""><textarea id="ozgecmis" name="comments" cols="25" rows="5"></textarea><br></td></tr> <tr><td>Meslek</td><td class="data"><input type="text" name="email" id="meslek"></td></tr> <tr><td>Unvan</td><td class="data"><input type="text" name="email" id="unvan"></td></tr> <tr><td>Uzmanlık Alanı</td><td class="data"><input type="text" name="email" id="uzmanlik_alani"></td></tr> <tr><td> Rol Seçmek İstiyorum</td><td class="data"><input id="rol_enable" onchange="disableEnableRol(this)" type="checkbox" name="vehicle" value="Bike"></td></tr> <tr><td>Rol İsteği</td><td class="data"><select id="rolselect" disabled> <option value="yazar">Yazar</option> <option value="hakem">Hakem</option> <option value="editor">Editör</option> </select></td></tr> <tr><td><button type="button" onClick="uyeOl()">Üye Ol</button></td></tr> </table>';
}

function disableEnableRol(checkBox){
	if(checkBox.checked==false){
		document.getElementById("rolselect").disabled=true;
	}
	else{
		document.getElementById("rolselect").disabled=false;
	}
}

function ucListeyiBirbirindenAyir(text){
	var temp=text.split("<#>");
	konu_listesi=temp[0].split("|");
	bilim_dali_listesi=temp[1].split("|");
	dergi_listesi=temp[2].split("|");
}

function dergiSayiSplit(text){
	dergi_sayi_listesi=text.split("|");
}

function sayiMakaleSplit(text){
   sayi_makale_listesi=text.split("|");	
}

function makaleAc(makale_yolu,makale_pk){
	alert("Bunun için üye olmanız gereklidir");
}

function tumDergiler(konu_pk,bilim_dali_pk){
	var xmlhttp;
	
	if (window.XMLHttpRequest)  	
 		 xmlhttp=new XMLHttpRequest(); 	 
  
	else  	
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

	xmlhttp.onreadystatechange=function()
	{  
  		if (xmlhttp.readyState==4 && xmlhttp.status==200){
  			var code="";
  			var counter;
  			ucListeyiBirbirindenAyir(xmlhttp.responseText);
  			code+='<select id="konu_listesi" style="margin-top:30px"><option value="-1">Tümü</option>';
  			if(konu_listesi.length!=1){
  				counter=(konu_listesi.length-1)/2;
				for(var i=0;i<counter;i++){
  					code+='<option value="'+konu_listesi[i*2]+'">'+konu_listesi[i*2+1]+'</option>';
  				}
  			}
  			code+='</select>';
  			
  			code+='<select id="bilim_dali_listesi" style="margin-top:30px;margin-left:20px"><option value="-1">Tümü</option>';
  			if(bilim_dali_listesi.length!=1){
  				counter=(bilim_dali_listesi.length-1)/2;
				for(var i=0;i<counter;i++){
  					code+='<option value="'+bilim_dali_listesi[i*2]+'">'+bilim_dali_listesi[i*2+1]+'</option>';
  				}
  			}
  			
  			code+='</select>';
  			
  			code+='<button style="margin-top:30px;margin-left:20px;" type="button" onClick="tumDergiler(document.getElementById(\'konu_listesi\').value,document.getElementById(\'bilim_dali_listesi\').value)">Listele</button>';
  			
			if(dergi_listesi.length!=1){
  				
				counter=(dergi_listesi.length-1)/4;
  				
  				code+='<br><table border="1" style="margin-top:10px">';
  				code+='<tr><td><b>Dergi İsmi</b></td><td><b>ISBN</b></td><td><b>Yayınlanmış Sayı</b></td><td><b>Sayı Listesi</b></td><td><b>Makale Listesi</b></td><td><b>Makaleyi Aç</b></td></tr>';
  				for(var i=0;i<counter;i++){
  					
  					code+='<tr><td>'+dergi_listesi[i*4+1]+'</td><td>'+dergi_listesi[i*4+2]+'</td><td>'+dergi_listesi[i*4+3]+'</td><td id="sayi_goster_alani'+i+'" >';
  					
  					if(dergi_listesi[i*4+3]=='0'){
  						code+='<button type="button" disabled>Sayı Listele</button>';
  					}
  					else{
  						code+='<button type="button" onClick="dergiSayiGoster('+dergi_listesi[i*4]+','+i+')">Sayı Listele</button>';
  					}
  					
  					code+='</td><td id="makale_listele_alani'+i+'" >Sayı Seçilmedi</td><td><button id="makale_ac_butonu'+i+'" type="button" onClick="makaleAc(document.getElementById(\'sayi_makale_listesi'+i+'\').value)" disabled>Makaleyi Aç</button></td></tr>';
  					
  					
  					
  				}
  				code+="</table><br>";
  			}
  			else{
  				code+='<br><p>Bu filtrelemede sisteme kayıtlı herhangi bir dergi bulunmamaktadır</p>';
  			}
  			document.getElementById("panel").innerHTML=code;
  		}   	
  		
 	}
	
	xmlhttp.open("GET","http://localhost:8080/yazgellab/tumdergilerilistele.action?konu_pk="+konu_pk+"&bilim_dali_pk="+bilim_dali_pk,true);
	xmlhttp.send(null);
}

function dergiSayiGoster(dergi_pk,i){
	var xmlhttp;
	
	if (window.XMLHttpRequest)  	
 		 xmlhttp=new XMLHttpRequest(); 	 
  
	else  	
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
			var code="";
  			var counter;
  			dergiSayiSplit(xmlhttp.responseText);
  			code+='<select id="sayi_select_listesi'+i+'" onChange="sayiMakaleListele(this.value,'+i+')" >';
  			if(dergi_sayi_listesi.length!=1){
  				counter=(dergi_sayi_listesi.length-1)/3;
				for(var j=0;j<counter;j++){
  					code+='<option value="'+dergi_sayi_listesi[j*3]+'">'+dergi_sayi_listesi[j*3+1]+'</option>';
  				}
  			}
  			code+='</select>';
  			document.getElementById("sayi_goster_alani"+i).innerHTML=code;
  			sayiMakaleListele(document.getElementById("sayi_select_listesi"+i).value,i);
  			
		}
	}
	
	xmlhttp.open("GET","http://localhost:8080/yazgellab/dergisayilistele.action?dergi_pk="+dergi_pk,true);
	xmlhttp.send(null);
}

function sayiMakaleListele(sayi_pk,i){
	var xmlhttp;
		
		if (window.XMLHttpRequest)  	
	 		 xmlhttp=new XMLHttpRequest(); 	 
	  
		else  	
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200){
				var code="";
	  			var counter;
	  			sayiMakaleSplit(xmlhttp.responseText);
	  			code+='<select id="sayi_makale_listesi'+i+'">';
	  			if(sayi_makale_listesi.length!=1){
	  				counter=(sayi_makale_listesi.length-1)/3;
					for(var j=0;j<counter;j++){
	  					code+='<option value="'+sayi_makale_listesi[j*3+2]+'">'+sayi_makale_listesi[j*3+1]+'</option>';
	  				}
	  			}
	  			code+='</select>';
	  			document.getElementById("makale_ac_butonu"+i).disabled=false;
	  			document.getElementById("makale_listele_alani"+i).innerHTML=code;
			}
		}
		
		xmlhttp.open("GET","http://localhost:8080/yazgellab/sayimakalelistele.action?sayi_pk="+sayi_pk,true);
		xmlhttp.send(null);
	}

</script>
</head>
<body>
<div id="maincontainer">
	<div id="maindiv1">
		<div id="banner"></div>
		<div id="login">
			<form action="login.action" id="form" method="POST" name="form">
E-mail:
	<input id="e_mail" type="text" name="e_mail" size="20"></input><br>
Sifre:
	<input id="sifre" style="margin-left: 13px" type="password" name="sifre" size="20"></input><br>
	<input type="button" value="Giris Yap" onclick="login()"></input>
	<input type="button" value="Uye ol" onclick="register()"></input>
	<input id="admingirisi" type="checkbox" name="admincheck" value="Admin">Admin Girisi</input>
</form>
		</div>
	</div>
	<div id="maindiv2">
		<div id="menu">
		<div id="navigation">
			<ul class="top-level">
        <li><a href="index.jsp">ANASAYFA</a>
        </li>
        <li><a href="#" onClick="tumDergiler(-1,-1)">TÜM DERGİLER</a>
        </li>
        <li><a href="#" onClick="listele()">TÜM MAKALELER</a>
        </li>
        <li><a href="#">ARAMA</a>
        </li>
    </ul>		
    </div>
		</div>
		<div id="panel">
			<p style="margin-top:30px"><b>Merhaba Ziyaretçi ! Demir Yayıncılık resmi web sitesine hoşgeldin..</b></p>
			<p style="margin-left:20px"> Sitemizde kayıtlı olan dergileri inceleyebilir,yayınlanmış makalelerden faydalanabilirsin.</p>
			<p style="margin-left:20px"> Tabi önce üye olmak kaydıyla :) </p>
			<p style="margin-left:350px"> İyi eğlenceler dileriz..</p>
			<p style="margin-left:350px"> Demir Yayıncılık Yönetimi </p>
		</div>
	</div>
	<div id="maindiv3">
		<div id="footer">
			<a href="" style="font-size:30;margin-top:55px;margin-left:65px;float:left;text-decoration: none">HAKKIMIZDA</a>
			<a href="" style="margin-left:65px;margin-top:55px;float:left;text-decoration: none">ILETISIM</a>
			<p style="margin-left:65px;float:left;margin-top:55px"> @DemirYayincilik2012 | Her hakki saklidir...</p>
		</div>
	</div>
</div>
</body>
</html>